import os
from pprint import pprint

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

# todo 配置数据库

db = SQLAlchemy()
# todo 配置日志信息
import logging.config
from config.log_manager import LOGGING_DIC

logging.config.dictConfig(LOGGING_DIC)  # 导入上面定义的logging配置
logger = logging.getLogger("loggers")  # 生成一个log实例


class Application(Flask):
    """扩展插件类"""

    def __init__(self, import_name):
        super(Application, self).__init__(import_name)
        if "project_env" in os.environ:
            self.config.from_pyfile(f"config/{os.environ['project_env']}.py")
        else:
            self.config.from_pyfile(f"config/base.py")
        # self.static_folder = "/Users/gaven/Desktop/flask_demo/statics"   # 绝对路径  不建议写  404
        # self.static_url_path = "/excal"  # 会转换为元组进行转换，不建议写  :bug 会直接报错
        db.init_app(self)
        pprint(self.config)


app = Application(__name__)
from urls import register_url

register_url(app)
app.app_context().push()
